how to detect js module was required

45

how to detect js module was required -

if (require.main === module) {
    console.log('called directly');
} else {
    console.log('required as a module');
}

Comments

Submit
0 Comments